<template>
	<view class="my-rent">
		<view class="rent-item" v-for="v in itemsData" :key="v.id">
			<view class="item-top">
				<view class="item-box" @click="house(v.id)">
					<view class="item-top-left">
						<uni-badge class="tip" :text="v.rentrentStatus" type="primary" absolute="leftTop" :offset="[14, 5]">
							<image :src="v.housePhoto" mode="" :style="'opacity:'+(v.rentrentStatus=='已下架'?'0.5':'1')"></image>
						</uni-badge>
					</view>
					<view class="item-top-right">
						<h4 :class="[v.rentStatus=='已下架'?'takedown':'']">{{v.rentalWay}} {{v.housingInformation}}</h4>
						<text class="area" :class="[v.rentStatus=='已下架'?'takedown':'']">{{v.buildingArea}}</text>
						<text class="money" :class="[v.rentStatus=='已下架'?'takedown':'']">{{v.rent}}/月</text>
					</view>
				</view>
			</view>
			<view class="item-bottom">
				<view class="hire" v-if="v.rentStatus=='出租中'">
					<view class="down but" style="margin-right: 22rpx;" @click="open" :data-itdata="v">租出下架</view>
					<navigator  @click="goEdit(v.communityId)" hover-class="navigator-hover">
						<view class="edit but">编辑</view>
					</navigator>
				</view>
				<view class="rehirebox" v-else>
					<navigator @click="goEdit(v.communityId)" hover-class="navigator-hover">
						<view class="rehire but" >重新上架</view>
					</navigator>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="tishi">
				<view class="tishi-top">确定删除此房屋信息吗？</view>
				<view class="tishi-sel">
					<text @click="closeno">否</text>
					<text @click="closeyes">是</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {http} from "../../utils/http.js"
	export default {
		data() {
			return {
				itemsData: [],
				// 点击的状态
				dotrentStatus: "",
				id:null
			};
		},
		methods: {
			getData() {
				http({
					url: "/houseRent/list",
					method: "post",
				}).then(({data}) => {
					this.itemsData=data;
				})
			},
			house(v) {
				uni.navigateTo({
					url: '../HouseRental/houseDetails/houseDetails?id=' + v
				});
			},
			open(e) {
				this.$refs.popup.open('top')
				this.dotrentStatus = e.currentTarget.dataset.itdata.rentStatus
				this.id=e.currentTarget.dataset.itdata.id
				console.log(this.dotrentStatus)
				console.log(this.id)
			},
			goEdit(v){
				uni.navigateTo({
					url: '../confirmHouseMag/confirmHouseMag?communityId=' + v
				});
			},
			closeno(e) {
				this.$refs.popup.close()
				console.log(e)
			},
			closeyes(e) {
				console.log(e)
				this.$refs.popup.close()
				this.dotrentStatus = "已下架";
				http({
					url:"/houseRent/updateStatus",
					method:"put",
					data:{
						id:this.id,
						rentStatus:this.dotrentStatus
					}
				})
				this.getData();
			},
			
			
		},
		onLoad() {
			this.getData()
		}
	}
</script>

<style lang="less">
	.my-rent {
		padding: 40rpx;

		.rent-item {
			padding: 26rpx;
			display: flex;
			flex-direction: column;
			border-radius: 8rpx;
			box-shadow: 0px 0px 15rpx rgba(0, 0, 0, .2);
			margin-bottom: 30rpx;

			.item-top {

				display: flex;
				border-radius: 8rpx;
				margin-bottom: 24rpx;

				.item-box{
					display: flex;
					.item-top-left {
						margin-right: 28rpx;
					
						image {
							width: 216rpx;
							height: 160rpx;
							border-radius: 10rpx;
						}
					}
					
					.item-top-right {
						height: 160rpx;
						display: flex;
						flex-direction: column;
						align-items: flex-start;
						justify-content: space-between;
					
						h4 {
							font-size: 32rpx;
							// margin-bottom: ;
						}
				}

					.area {
						font-size: 26rpx;
						color: #a0a0a0;
					}

					.money {
						font-size: 28rpx;
						color: #f25867;
					}
				}

			}

			.item-bottom {
				display: flex;
				align-items: center;
				border-top: 1px dashed #ccc;
				padding-top: 24rpx;

				.hire {
					display: flex;
				}

				.but {
					width: 298rpx;
					height: 80rpx;
					text-align: center;
					line-height: 80rpx;
					border-radius: 10rpx;
					font-size: 32rpx;

				}

				.down {
					background-color: #e5f1ff;
					color: #006fff;
				}

				.edit {
					background-color: #006fff;
					color: white;
				}

				.rehirebox {
					flex: 1;
					display: flex;
					justify-content: flex-end;

					.rehire {
						float: right;
						background-color: #e5f1ff;
						color: #006fff;
					}
				}


			}
		}

		.tishi {
			margin: 300rpx auto;
			width: 600rpx;
			background-color: white;
			border-radius: 8rpx;

			.tishi-top {
				height: 150rpx;
				padding-left: 50rpx;
				line-height: 150rpx;
			}

			.tishi-sel {
				border-top: 1px solid #eee;
				display: flex;
				align-items: c1;

				text {
					flex: 1;
					height: 80rpx;

					text-align: center;
					line-height: 80rpx;
					font-size: 32rpx;

				}

				text:nth-child(1) {
					border-right: 1px solid #eee;
				}
			}
		}
	}

	.takedown {
		color: #d6d6d6 !important;
	}
</style>
<style lang="less">
	.my-rent {
		.uni-badge {

			width: 128rpx !important;
			height: 46rpx !important;
			padding: 0rpx !important;
			background-color: #28d779 !important;
			color: white;
			border-radius: 10rpx !important;
			text-align: center !important;
			line-height: 44rpx !important;
			font-size: 26rpx !important;
			border: 0rpx !important;
			opacity: ;
		}
	}
</style>
